package com.le.tester.book.concurrentchallenge.threadSafedelegation;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * createTime：2025-03-17 10:08
 * description：车辆底层追踪
 */
public class PublishingVehicleTracker {

    private final Map<String, SafePoint> location;

    private final Map<String, SafePoint> unmodifiableMap;

    public PublishingVehicleTracker(Map<String, SafePoint> location) {
        this.location = new ConcurrentHashMap<>(location);
        this.unmodifiableMap = Collections.unmodifiableMap(this.location);
    }

    public Map<String, SafePoint> getLocation() {
        return unmodifiableMap;
    }

    public SafePoint getLocations(String id) {
        return location.get(id);
    }

    public void setLocation(String id, int x, int y) {
        if (!location.containsKey(id)) {
            throw new IllegalArgumentException();
        }
        location.get(id).set(x, y);
    }
}
